﻿using UnityEngine;
using System.Collections;

public class FastTapGame : GenericGame {
	
	public GUIText firstPlayerScore;
	public GUIText secondPlayerScore;
	public GUIText timer;
	public GUIText results;
	
	private int fScore = 0;
	private int sScore = 0;
	
	private float gameDuration = 10;
	private bool gameOver = false;
	
	// Use this for initialization
	void Start () 
	{
		results.enabled = false;
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(!gameOver)
		{
			gameDuration -= Time.deltaTime;
			
			if(gameDuration <= 0)
			{
				gameOver = true;	
			}
			
			if(Input.GetKeyDown(KeyCode.Q))
			{
				fScore++;
				firstPlayerScore.text = fScore.ToString();
			}
			if(Input.GetKeyDown(KeyCode.P))
			{
				sScore++;
				secondPlayerScore.text = sScore.ToString();
			}
				
			timer.text = "0:" + gameDuration.ToString("F0");
		}
		else
		{
			timer.enabled = false;
			results.enabled = true;
			
			if(fScore > sScore)
			{
				results.text = "First Player Wins: " + fScore.ToString();
			}
			else if(fScore < sScore)
			{
				results.text = "Second Player Wins: " + sScore.ToString();
			}
			else
			{
				results.text = "Draw: " + fScore.ToString() + " - " + sScore.ToString();
			}
		}
	}
}
